<?php
/**
 * [WeEngine System] Copyright (c) 2013 WE7.CC
 * User: fanyk
 * Date: 2017/10/14
 * Time: 18:56
 */

namespace Ken\Wechat;


use GuzzleHttp\Client;

class WechatApi {
	const TEMPURL = 'http://api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s';

	public function token() {
		return 'wEZSz8AmOn5NVXsAfuoURrF0DfuAwbo4PbeoiQYUz862tlVLqnMkbFBFt0ueT9DRwTch5UNCMLK-6Bvv58p7wLjlauvIqLLd_JU1uPPgx2RY-7HJmWFafdpX9L_ZfaoIXGYgABASBT';
	}
	private function isTemp() {
		return false;
	}
	public function put($path, $content = null) {

		$url = sprintf(self::TEMPURL, $this->token(), 'image');

		$this->uploadfile($url, $path);

	}

	private function uploadfile($url, $content) {
		$client = new Client();
		$items[] = [
			'name' => 'testimg',
			'contents' => fopen($content, 'r'),
		];
		$client = new Client();
		$response = $client->post($url,[
			'multipart'=>$items,
			'debug'=>true
		]);
		var_dump($response->getBody()->getContents());
		return $response->getStatusCode() == 200;

	}
}